﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Library;
using System.Data;
using IHISCETeim.BLL;
using System.Text;
using IHISCETeim.Model;


namespace IHISCETeim.Web.MachineSys.FTradeModel
{
    public partial class ReportZhanLin2EasyUI : EasyUIPageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "ReportZhanLin2EasyUI";
            }
        }

        //protected string LastMonthDay
        //{
        //    get
        //    {
        //        return Convert.ToDateTime(DateTime.Now.AddMonths(1).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
        //    }
        //}

        protected string GetXiaoShouLeiXing()
        {
            List<FTradeSaleTypeConfigInfo> list = FTradeSaleTypeConfigController.GetAll();
            StringBuilder sb = new StringBuilder();
            string JSONTemp = "{{label: '{0}',value: '{1}'}},";
            sb.Append("");
            foreach (FTradeSaleTypeConfigInfo itm in list)
            {
                sb.AppendFormat(JSONTemp, itm.XiaoShouLeiXing, itm.XiaoShouLeiXing);
                // sb.AppendFormat("<option value=\"{0}\" {1}>{0}</option>", itm.XiaoShouLeiXing, itm.XiaoShouLeiXing == XiaoShouLeiXing ? "selected" : "");
            }

            return sb.ToString().Substring(0, sb.ToString().Length - 1);
        }

        //收款条件
        private string _XiaoShouLeiXing = "";
        protected string XiaoShouLeiXing
        {
            get
            {
                if (_XiaoShouLeiXing == "")
                    _XiaoShouLeiXing = GetRequestValue<string>("XiaoShouLeiXing", "");
                return _XiaoShouLeiXing;
            }
            set
            {
                _XiaoShouLeiXing = value;
            }
        }
        protected string JingXiaoShang
        {
            get
            {
                return GetRequestValue<string>("JingXiaoShang", "");

            }
        }

        protected string GetSQLWhere()
        {
            //营业经理权限 2014-02-21
            string agentList = base.FTradeAgentPowerSqlWhere();
            string wheresql = string.IsNullOrEmpty(agentList) ? " 1=1 " : string.Format(" JingXiaoShang in ({0})", agentList);

            string sqlcommonFiled = "";
            if (!string.IsNullOrEmpty(JingXiaoShang))
            {                
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("JingXiaoShang", QueryOperatorsEnum.包含, JingXiaoShang);
             
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }

            }


           

            if (XiaoShouLeiXing != "")
            {
                string[] xslxs = XiaoShouLeiXing.Split(new char[] { ',' });
                string xslxsql = " XiaoShouLeiXing in (''";
                foreach (string itm in xslxs)
                {
                    if (!string.IsNullOrEmpty(itm))
                    {
                        xslxsql += string.Format(",'{0}'", itm);
                    }
                }
                xslxsql += ")";

                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + xslxsql;
                }
                else
                {
                    wheresql = xslxsql;
                }
            }

            return wheresql;
        }


        protected override string query()
        {
            DataTableCollection dts = FTradeReportController.Report2GetReportDate(GetSQLWhere());


            return ToDataGridJson(dts[0], TotalCount, dts[1]).ToString();
        }


        
    }
}